/*
 * FileName: factory.cc
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-16 15:54:16
 * Version: 1.0
 * Description: 工厂方法
 */
#include <iostream>
#include <memory>
#include <string>
using namespace std;

enum CarType{BMW,AUDI};

class Car 
{
public:
	Car(string name):name_(name){}
	virtual void show() = 0;
protected:
	string name_;
};

class Bmw:public Car
{
public:
	Bmw(string name):Car(name){}
	void show(){cout<<"获取一辆宝马汽车"<<endl;}
};

class Audi:public Car
{
public:
	Audi(string name):Car(name){}
	void show(){cout<<"获取一辆奥迪汽车"<<endl;}
};

//工厂方法
class Factory
{
public:
	Factory(){}
	virtual Car* createCar(string name) = 0;
};

//宝马工厂
class BmwFactory : public Factory
{
public:
	Car* createCar(string name){return new Bmw(name);}
};

//奥迪工厂
class AudiFactory:public Factory
{
public:
	Car* createCar(string name){return new Audi(name);}
};

int main()
{
	unique_ptr<Factory> bmwfty(new BmwFactory());
	unique_ptr<Factory> audifty(new AudiFactory());

	unique_ptr<Car> p1(bmwfty->createCar("X6"));
	unique_ptr<Car> p2(audifty->createCar("A8"));

	p1->show();
	p2->show();
	
	return 0;
}
